package cn.sfturing.service.impl;

import cn.sfturing.dao.AdminMapper;
import cn.sfturing.entity.Admin;
import cn.sfturing.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value ="AdminService" )
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public List<Admin> queryAll(Admin admin) {
        return adminMapper.queryAll(admin);
    }

    @Override
    public Admin queryByName(String AdName) {
        return adminMapper.queryByName(AdName);
    }

    @Override
    public Boolean insertAdmin(String AdName, String password) {
        Boolean TF=false;
        if(adminMapper.queryByName(AdName) == null){
            int i = adminMapper.insertAdmin(AdName, password);
            if(i>0)TF=true;
        }
        return TF;
    }

    @Override
    public Boolean updatePassword(Admin admin) {
        Boolean TF=false;
        int i = adminMapper.updatePassword(admin);
        if(i>0)TF=true;
        return TF;
    }

    @Override
    public Boolean del(Integer id) {
        Boolean TF=false;
        int i = adminMapper.del(id);
        if(i>0)TF=true;
        return TF;
    }

    @Override
    public Boolean verifyAdmin(Admin admin) {
        Boolean TF=false;
        Admin admin1 = adminMapper.queryByName(admin.getAdName());
        if(admin1!=null){
            if(admin1.getPassword().equals(admin.getPassword())){
                TF=true;
            }
        }
        return TF;
    }

    @Override
    public boolean addAdmin(Admin admin) {
        return adminMapper.addAdmin(admin)>0?true:false;
    }
}
